﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using Telerik.Web.UI;
using System.Globalization;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class DC_DisciplineCommand : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        Command_DisciplineBLL salaryCommandBLL = new Command_DisciplineBLL();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //this.lblDate.Text = DateTime.Today.ToString();
                LoadDataGrid();
            }
            
        }
        
        private void LoadDataGrid()
        {
            try
            {
                DataSet ListSalaryCommand = salaryCommandBLL.ListSalaryCommand(901,"");
                DataTable table = ListSalaryCommand.Tables[0];
                DataColumn dc = new DataColumn("No", System.Type.GetType("System.String"));
                table.Columns.Add(dc);

                foreach (DataRow row in table.Rows) // Loop over the rows.
                {
                    if (row["cmd_status"].ToString() == "W")
                        row["No"] = row["cmd_draft_no"];
                    else
                        row["No"] = row["cmd_ref_no"];
                }

                table.AcceptChanges();
                RadGrid2.DataSource = ListSalaryCommand.Tables[0];
                RadGrid2.DataBind();


            }
            catch (Exception ex)
            {

            }
        }

        protected void RadGrid2_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["cmd_seq"]);
                salaryCommandBLL.DeleteSalaryCommand(seq, ssMng.EmpSeq);
            }
            LoadDataGrid();
        }

        protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
        {

            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                string scr;
                if (e.Item.Cells[9].Text == "1")
                { scr = "<img src='../Images/Buttons/Update.gif'>"; }
                else
                    scr = "<img src='../Images/Buttons/Cancel.gif'>";
                { e.Item.Cells[9].Text = scr; }

                string strTmp;
                DateTime dateTmp;
                
                strTmp = e.Item.Cells[8].Text;
                dateTmp = Convert.ToDateTime(strTmp);  
 
                e.Item.Cells[8].Text = dateTmp.ToString("dd/MM/yyyy", new CultureInfo("th-TH"));


            }

        }
    }
}
